/*
 * Copyright 2012 Ufonzak.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cz.muni.fi.heathtow.web.pages;

import cz.muni.fi.heathrowapi.HeathrowRoles;
import cz.muni.fi.heathtow.web.auth.SecureWicketAuthenticatedWebSession;
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;

public class MainPage extends WebPage
{
    public MainPage(final PageParameters parameters)
    {
        super(parameters);
        
        add(new BookmarkablePageLink("homeLink", HomePage.class));
        add(new BookmarkablePageLink("flightsLink", FlightsView.class));
        add(new BookmarkablePageLink("stewardsLink", StewardView.class));
        add(new BookmarkablePageLink("destinationsLink", DestinationView.class));
        add(new BookmarkablePageLink("aircraftLink", AircraftView.class));
        BookmarkablePageLink users = new BookmarkablePageLink("usersLink", UsersView.class);
        add(users);
        MetaDataRoleAuthorizationStrategy.authorize(users, RENDER, HeathrowRoles.ADMIN);
        
        add(new BookmarkablePageLink("homeLink2", HomePage.class));
        add(new BookmarkablePageLink("flightsLink2", FlightsView.class));
        add(new BookmarkablePageLink("stewardsLink2", StewardView.class));
        add(new BookmarkablePageLink("destinationsLink2", DestinationView.class));
        add(new BookmarkablePageLink("aircraftLink2", AircraftView.class));
        
        BookmarkablePageLink signOut = new BookmarkablePageLink("signOut", SignOut.class);
        add(signOut);
        signOut.setVisible(!SecureWicketAuthenticatedWebSession.get().getRoles().equals(new Roles()));
        Label user = new Label("currentUser", new PropertyModel<String>(this, "session.user"));
        add(user);
        user.setVisible(!SecureWicketAuthenticatedWebSession.get().getRoles().equals(new Roles()));
        
        Label logged = new Label("logged", new StringResourceModel("loggedAs", this, null));
        add(logged);
        logged.setVisible(!SecureWicketAuthenticatedWebSession.get().getRoles().equals(new Roles()));
        
        BookmarkablePageLink signIn = new BookmarkablePageLink("signIn", SignIn.class);
        add(signIn);
        signIn.setVisible(SecureWicketAuthenticatedWebSession.get().getRoles().equals(new Roles()));
    }
}
